package com.zhl.emp_manage.mapper;

import com.zhl.emp_manage.entity.Emp;
import org.apache.ibatis.annotations.*;

import java.util.List;


public interface EmpMapper {

    //查询全部
    @Select("select * from emp")
    List<Emp> getEmpAll();

    //新增
    @Insert("insert into emp (id,emp_name,emp_age,emp_desc,emp_salary,belong_dept) values (#{id},#{empName},#{empAge},#{empDesc},#{empSalary},#{belongDept})")
    boolean addEmp(Emp emp);

    //修改
    @Update("update emp set emp_name=#{empName},emp_age=#{empAge},emp_salary=#{empSalary},emp_desc=#{empDesc},belong_dept=#{belongDept} where id=#{id}")
    boolean updateEmp(Emp emp);

    //删除
    @Delete("delete from emp where id=#{id}")
    boolean deleteEmp(Integer id);

    //根据id查询
    @Select("select * from emp where id=#{id}")
    Emp getById(Integer id);

    //分页查询
    List<Emp> getEmp(Integer page, Integer limit);

    //模糊查询
    @Select("select * from emp where emp_name like CONCAT('%',#{empName},'%')")
    List<Emp> getEmpLike(String name);

    //查询部门下的所有员工
    @Select("select e.*,d.dept_name from emp e LEFT JOIN dept d on e.belong_dept=d.dept_num where d.dept_num=#{deptNum}")
    List<Emp> getEmpByDeptNo(Integer deptNo);

    //动态返回查询结果
    @Select("<script>" +
            "select" +
            "<foreach collection='wrapper' item='items' separator=','>" +
            "${items}" +
            "</foreach>" +
            "from emp where id=#{id}" +
            "</script>")
    Emp queryWrapper(@Param(value = "wrapper") List<String> wrapper, Integer id);
}
